package com.ecoolex.chinadutyfree.retailer.api.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ecoolex.chinadutyfree.retailer.ws.PaymentOrderService;


@RestController
@RequestMapping("/payment/order")
@CrossOrigin(origins = "*",maxAge = 3600)
public class PaymentOrderController {
	
	private Logger log = LoggerFactory.getLogger(PaymentOrderController.class);
	
	@Reference
	private PaymentOrderService paymentOrderService;
	
	@PostMapping("/notify/pay")
    public void payNotify(HttpServletRequest req, HttpServletResponse response) throws Exception{
        log.debug("支付通知[/payment/order/notify/pay]: req={}", req);
        paymentOrderService.orderNotify(req,response, PaymentOrderController.class.getSimpleName());
    }
	
	@PostMapping("/notify/refund")
    public void refundNotify(HttpServletRequest req, HttpServletResponse response) throws Exception{
        log.debug("退款通知[/payment/order/notify/refund]: body={}", req);
        paymentOrderService.refundNotify(req,response, PaymentOrderController.class.getSimpleName());
    }
	
	@PostMapping("/front-notify/pay")
	public void payFrontNotify(HttpServletRequest req, HttpServletResponse response) throws Exception{
		log.debug("前台退款通知[/payment/order/front-notify/refund]: body={}", req);
		paymentOrderService.payFrontNotify(req, response);
	}
}
